package com.yanqu.road.server.cmd.cookboy.process2.cross;

import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_COOK_BOY2_SERVE_DISH, desc = "同步开宴")
public class CrossCookServeFoodCmd extends AbstractCommand {

	private long userId;
	private int activityId;


	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		CookBoyProto.CookBoy2OpenTableRespMsg crossSyncMsg = CookBoyProto.CookBoy2OpenTableRespMsg.parseFrom(packet.getBytes());
		userId = packet.getPlayerId();
		activityId = crossSyncMsg.getActivityId();
		if(crossSyncMsg.getRet() == 0){
			CookBoyMgr.syncFoodServe(activityId,userId,crossSyncMsg);
		}else{
			//上菜失败状态改回来
			CookBoyMgr.backFoodServe(activityId,userId,crossSyncMsg);
		}
		CookBoyProto.CookBoy2RecordRespMsg.Builder respMsg = CookBoyProto.CookBoy2RecordRespMsg.newBuilder();
		respMsg.setRet(crossSyncMsg.getRet());
		GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(userId);
		gamePlayer.sendPacket(Protocol.U_COOK_BOY2_SERVE_DISH, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
